//
//  LVCircleMaskView.m
//  Live
//
//  Created by RoyLei on 16/7/14.
//  Copyright © 2016年 Heller. All rights reserved.
//

#import "LVCircleMaskView.h"
#import "BNDConstance.h"

@implementation LVCircleMaskView

- (void)setCirclePercent:(CGFloat)circlePercent {
    _circlePercent = circlePercent;
    [self setNeedsDisplay];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        
        _heightBeginToRefresh = kLVRefreshCircleViewHeight;
        _circlePercent = 0;
        
        CALayer *maskLayer = [CALayer layer];
        maskLayer.contents = (id)[[UIImage imageNamed:@"Ressources.bundle/angle-mask@2x.png"] CGImage];
        maskLayer.frame = self.bounds;
        self.layer.mask = maskLayer;
        
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetStrokeColorWithColor(context, UIColorWithHex(0x3b3b4c).CGColor);
    CGContextSetLineWidth(context, 2.f);
    
    CGFloat radius = 12;
    
    static CGFloat startAngle = 3 * M_PI / 2.0;
    CGFloat endAngle = ABS(_circlePercent) * (M_PI * 19 / 10) + startAngle;
    CGContextAddArc(context, CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2, radius, startAngle, endAngle, 0);
    
    CGContextDrawPath(context, kCGPathStroke);
}

@end
